$(document).ready(function() {
    //JS Menu LEft
    $('#navleft > li > a').click(function(){
        if ($(this).attr('class') != 'active'){
            $('#navleft li ul').slideUp();
            $(this).next().slideToggle();
            $('#navleft li a').removeClass('active');
            $(this).addClass('active');
        }
    });

    //JS Joom Detail
    $('.jqzoom').jqzoom({
        zoomType: 'innerzoom',
        preloadImages: false,
        alwaysOn:false
    });

    //JS Joom get val popup
    $('.btnZoom').click(function(){
        var img_href = $('#imgmax').attr('href');
        $('.btnZoom').attr('href', img_href);
    });

    //JS mycarousel load relative producs
    $('#mycarousel').jcarousel({
        wrap: 'circular',
        animation: 'fast',
        scroll: 1,
        auto: true,
        transitions: Modernizr.csstransitions ? {
            transforms:   Modernizr.csstransforms,
            transforms3d: Modernizr.csstransforms3d,
            easing:       'ease'
        } : false
    });

    // Close Tab Check out (Popup shopping bag) and Hide background when mouse leave
    var x;
    $('#ppShoppingbag').mouseleave(function() {
        x = setTimeout("$('#ppShoppingbag .close-reveal-modal').click()",3000 );
    });
    $('#ppShoppingbag').mouseenter(function() {
        clearTimeout(x);
    });

    //JS for checkout page (col-right-checkout)...
    $(".inner-lb").hide();
    $('.lb1,.lb3').click(function(){
        $(".inner-lb").hide();
    });
    $('.lbUden').click(function(){
        $(".inner-lb").show();
    });
    //JS for Checkout page (col-left-checkout)  ...
    $(".w-another-add").hide();
    $('.bnt-another-add').click(function(){
        $(".w-another-add").slideToggle();
    });

    //JS for Gavekort page...
    $(".other_amount_area").hide();
    $('.ipValue').click(function(){
        $(".other_amount_area").hide();
    });
    $('.ipEnterValue').click(function(){
        $(".other_amount_area").show();
    });

    //JS for...

    //$('.open-popup').click(function(e) {
    //    e.preventDefault();
    //    window.open(this.href, '_blank', 'width=500,height=300');
    //});



    //JS for Tooltip ...
    // initiate the plugin after DOM has loaded

    // fixed tooltip
    $('a.fixedTip').aToolTip({
        fixed: true
    });

    // List of all parameters and their default values:
    $('a.hastool').aToolTip({
        // no need to change/override
        closeTipBtn: 'aToolTipCloseBtn',
        toolTipId: 'aToolTip',
        // ok to override
        fixed: false,                   // Set true to activate fixed position
        clickIt: false,                 // set to true for click activated tooltip
        inSpeed: 200,                   // Speed tooltip fades in
        outSpeed: 100,                  // Speed tooltip fades out
        tipContent: '',                 // Pass in content or it will use objects 'title' attribute
        toolTipClass: 'defaultTheme',   // Set class name for custom theme/styles
        xOffset: 5,                     // x position
        yOffset: 5,                     // y position
        onShow: null,                   // callback function that fires after atooltip has shown
        onHide: null                    // callback function that fires after atooltip has faded out
    });

    //JS when hover SHopping-page show Popup...
    $( "#ppShoppingbag, .shopping-bag" ).mouseenter(function() {
        $( "#ppShoppingbag" ).addClass('visibility');
    });
    $( "#ppShoppingbag, .shopping-bag" ).mouseleave(function() {
        $( "#ppShoppingbag" ).removeClass('visibility');
    });
    $('.wrap-inner-Shoppingbag .close-reveal-modal').click(function() {
        $( "#ppShoppingbag" ).removeClass('visibility');
    });

    //JS for
    //JS for
    //JS for
});

function lazyLoad(data){
    var loadingId = '#' + data.loading_id;
    var resultId = '#' + data.result_id;

    $(loadingId + ' span').hide();
    $(loadingId + ' img').show();
    data.page++;

    if((data.page - 1) * data.limit < data.total){
        $.ajax({
            type: 'get',
            url: data.url.replace('{page}', data.page),
            success: function(res) {
                $(loadingId).hide();
                $(loadingId + ' span').show();
                $(loadingId + ' img').hide();

                $(resultId).after(res);
                $(resultId + ' a.hastool').aToolTip({
                    // no need to change/override
                    closeTipBtn: 'aToolTipCloseBtn',
                    toolTipId: 'aToolTip',
                    // ok to override
                    fixed: false,                   // Set true to activate fixed position
                    clickIt: false,                 // set to true for click activated tooltip
                    inSpeed: 200,                   // Speed tooltip fades in
                    outSpeed: 100,                  // Speed tooltip fades out
                    tipContent: '',                 // Pass in content or it will use objects 'title' attribute
                    toolTipClass: 'defaultTheme',   // Set class name for custom theme/styles
                    xOffset: 5,                     // x position
                    yOffset: 5,                     // y position
                    onShow: null,                   // callback function that fires after atooltip has shown
                    onHide: null                    // callback function that fires after atooltip has faded out
                });
            }
        });
    }

    return data.page;
}